package edu.ucollege.android;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import com.google.android.maps.*;

import edu.ucollege.android.R;

public class PlaceActivity extends MapActivity{
	MapView mapView;
	MapController mc;
	GeoPoint p;
	@SuppressWarnings("deprecation")
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_map);
		mapView = (MapView) findViewById(R.id.maps);
		mapView.setBuiltInZoomControls(true);
		mapView.setStreetView(true);
		mc = mapView.getController();
		String coordinates[] = {"40.7742", "-96.6512"};
		double lat = Double.parseDouble(coordinates[0]);
		double lng = Double.parseDouble(coordinates[1]);
		p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
		mc.animateTo(p);
		mc.setZoom(18);
		mapView.invalidate();
	}
	
	public boolean inKeyDown(int keyCode, KeyEvent event){
		MapController mc = mapView.getController();
		switch(keyCode){
			case KeyEvent.KEYCODE_3:
				mc.zoomIn();
				break;
			case KeyEvent.KEYCODE_1:
				mc.zoomOut();
				break;
		}
		return super.onKeyDown(keyCode, event);
		
	}
	
	public boolean onDoubleTap(MotionEvent e) {
	     int x = (int)e.getX(), y = (int)e.getY();;  
	     Projection p = mapView.getProjection();  
	     mapView.getController().animateTo(p.fromPixels(x, y));
	     mapView.getController().zoomIn();  
	  return true; 
	}
	
	public boolean onTouchEvent(MotionEvent event, MapView mapView){
		if(event.getAction() == 1){
			p = mapView.getProjection().fromPixels((int)event.getX(), (int) event.getY());
			
		}
		return false;
	}
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}
